#include "proto.h"

int main (void)
{
	int tcp_fd;
	struct sockaddr_in server_addr; 
	socklen_t  addr_len;
	char buf[MSGSIZE] = {0};

	tcp_fd = socket (AF_INET, SOCK_STREAM, 0);
	if (-1 == tcp_fd) {
		perror ("socket()");
		exit (1);
	}
	//请求连接
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons (atoi(SERVER_PORT));
	inet_aton (SERVER_IP, &server_addr.sin_addr);
	
	addr_len = sizeof (server_addr);
	if (-1 == connect (tcp_fd, (struct sockaddr *)&server_addr, addr_len))
	{
		perror ("connect()");
		goto ERROR;
	}
	read (tcp_fd, buf, MSGSIZE);
	puts (buf);
	close (tcp_fd);
	return 0;
ERROR:
	close (tcp_fd);
	exit (1);
}
